package my.mark.mybaibaoxiang.nhr.codeToName;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * @author wxming.
 * @date 2024/8/15.
 * @Description 信息完善度关键代码
 */

@Service
@Slf4j
public class InfoCompleteDegree {

    /**
     *
     * @param omData 某个区块的数据对象
     * @param fieldList 该区块必填字段码表list
     * @return 返回false表示完善了，返回true表示有必填字段没填。
     */
    private boolean compareCompleteNotAll(Object omData, List<String> fieldList){
        if(ObjectUtil.isNotEmpty(omData) && CollectionUtil.isNotEmpty(fieldList)){
            if (ClassUtil.isClassCollection(omData.getClass())) {
                Collection<?> omCollections = (Collection<?>)omData;
                for (Object omItem:omCollections) {
                    if(compareCompleteNotAllItem(omItem,fieldList)){
                        return true;
                    }
                }
            }else{
                return compareCompleteNotAllItem(omData,fieldList);
            }
        }
        return false;
    }


    /**
     *
     * @param omData 某个区块的数据对象-单项
     * @param fieldList 该区块必填字段码表list
     * @return 返回false表示完善了，返回true表示有必填字段没填。
     */
    private boolean compareCompleteNotAllItem(Object omData,List<String> fieldList){
        if(ObjectUtil.isNotEmpty(omData) && CollectionUtil.isNotEmpty(fieldList)){
            for (String fieldName:fieldList) {
                Object fieldValue = ReflectUtil.getFieldValue(omData,fieldName);
                if(ObjectUtil.isEmpty(fieldValue)){
                    log.info("信息完善度命中字段：{}",fieldName);
                    return true;
                }
            }
        }
        return false;
    }
}
